package com.kdgc.power.base.controller;

import com.kdgc.power.base.entity.BaseLink;
import com.kdgc.power.base.service.BaseLinkService;
import com.kdgc.power.fw.bean.JsonMsg;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Controller
@RequestMapping("BaseLink")
public class BaseLinkController {
    @Autowired
    private BaseLinkService baseLinkService;

    @ResponseBody
    @RequestMapping("page")
    public Object searchBaseLink(HttpServletRequest request, int page, int rows) {
        String linkName = request.getParameter("linkName");
        return baseLinkService.searchPage(  page, rows,linkName);
    }

    @ResponseBody
    @RequestMapping("findById")
    public Map<String, Object> findBaseLink(Integer id) {
        return baseLinkService.getMapEntity(id);
    }

    @ResponseBody
    @RequestMapping("save")
    public JsonMsg saveBaseLink(BaseLink baseLink) {
        boolean success = baseLinkService.saveOrUpdate(baseLink);
        return new JsonMsg(success);
    }

    @ResponseBody
    @RequestMapping("deleteById")
    public JsonMsg deleteBaseLink(Integer id) {
        int rows = baseLinkService.removeById(id);
        return new JsonMsg(rows == 1);
    }
}